﻿
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <script src="~/plugins/mzui/js/mzui.min.js"></script>
    <link href="~/plugins/mzui/css/mzui.min.css" rel="stylesheet" />
    <title>找回密码</title>
</head>
<body>
    <div class="page fade scale-from-center display in" style="overflow: hidden; z-index: 1207;" data-display-name="display1206">
        <div class="dock blur-lg" style="background: url('/images/logo.png') no-repeat center; background-size: cover; top: -2rem; right: -2rem; bottom: -2rem; left: -2rem"></div>
        <div class="dock flex flex-center">
            <div class="modal rounded">
                <div class="heading divider primary-pale">
                    <div class="title">找回密码</div>
                    <nav class="nav">
                        <a href="/home/denglu?lx=@Request.QueryString["lx"]" class="text-link">已有账号？立即登录</a>
                    </nav>
                </div>
                @using (Html.BeginForm("zhmm", "home", new { gid = Request.QueryString["gid"], lx = Request.QueryString["lx"] }, FormMethod.Post, new { @class = "content box", enctype = "multipart/form-data" }))
                {
                    <div class="control has-label-left">
                        <input id="shouji" name="account" type="text" class="input" onkeyup="value=value.replace(/[^\d]/g,'');" placeholder="注册手机号">
                        <label for="account"><i class="icon-phone"></i></label>
                        <div class="help-text text-red"></div>
                    </div>
                    <div class="control has-label-left">
                        <input type="text" name="yzm" placeholder="验证码" style="width:80px;">
                        <button type="button" id="btn" class="btn primary-pale">获取验证码</button>
                        <div class="help-text text-red"></div>
                    </div>
                    <div class="control has-label-left">
                        <input name="pwd" type="password" class="input" placeholder="设置你的新密码">
                        <label for="account"><i class="icon-key"></i></label>
                        <div class="help-text text-red"></div>
                    </div>
                    <div class="control">
                        <button type="button" id="ok" class="btn block primary" onclick="return ck();">设置新密码</button>
                    </div>
                }
            </div>
        </div>
        <a onclick="history.go(-1);" class="btn dock dock-bottom dock-right spin"><i class="icon-2x icon-times muted"></i></a>
    </div>
    <script>
        var wait = 120;
        document.getElementById("btn").disabled = false;
        function time() {
            if (wait == 0) {
                wait = 120;
                document.getElementById("btn").removeAttribute("disabled");
                document.getElementById("btn").innerHTML = "重新获取验证码";
            } else {
                wait--;
                document.getElementById("btn").setAttribute("disabled", true);
                document.getElementById("btn").innerHTML = "(" + wait + ")秒后可重发";
                setTimeout(function () {
                    time();
                }, 1000)
            }
        }
        $("#btn").click(function () {
            if ($("#shouji").val().length == 11) {
                $.ajax({
                    url: "/ajax/api.ashx",
                    data: "ff=yzm&shouji=" + $("#shouji").val() + "&lx=2&Cache=" + Math.random(),
                    type: "post",
                    cache: false,
                    timeout: 8000,
                    dataType: "json",
                    ContentType: "application/json; charset=utf-8",
                    async: false,//一定要是同步请求，否则会跳转；（ajax默认是异步的）
                    error: function () { document.getElementById("btn").removeAttribute("disabled"); alert("AJAX Error"); },
                    beforeSend: function () { document.getElementById("btn").setAttribute("disabled", true); },
                    success: function (data) {
                        if (data.resp.respCode == "000000") {
                            document.getElementsByClassName("help-text")[1].innerHTML = "已发送,有效期十分钟!" ;
                            time();
                        }
                        else {
                            document.getElementById("btn").removeAttribute("disabled");
                            document.getElementsByClassName("help-text")[1].innerHTML = "发送失败,原因:" + data.resp.templateSMS;
                        }
                    },
                });
            }
            else { document.getElementsByClassName("help-text")[1].innerHTML = "请输入正确的手机号"; }
        });
        function ck() {
            if (document.getElementsByName("account")[0].value.length != 11) {
                document.getElementsByClassName("help-text")[0].innerHTML = "请输入正确的11位手机号";
                return false;
            }
            else {
                document.getElementsByClassName("help-text")[0].innerHTML = "";
            }
            if (document.getElementsByName("yzm")[0].value.length != 4) {
                document.getElementsByClassName("help-text")[1].innerHTML = "验证码不对";
                return false;
            }
            else {
                document.getElementsByClassName("help-text")[1].innerHTML = "";
            }
            if (document.getElementsByName("pwd")[0].value.length < 5) {
                document.getElementsByClassName("help-text")[2].innerHTML = "密码最少需要6位";
                return false;
            }
            else {
                document.getElementsByClassName("help-text")[2].innerHTML = "";
            }
            document.getElementById('ok').innerText = "提交中...";
            document.getElementById('ok').disabled = true;
            document.forms[0].submit();
            return true;
        }
    </script>
</body>
</html>
